//
//  RegistrationViewModelTests.swift
//  PorscheRegistrationTests
//
//  Created by Jinzhu Liu on 2023/12/13.
//

import XCTest
import Combine
@testable import PorscheRegistration


class RegistrationViewModelTests: XCTestCase {
    
    private var cancellable = Set<AnyCancellable>()
    override func setUpWithError() throws {
        
    }

    override func tearDownWithError() throws {
        
    }
    
    func testAvatarColorSetting() {
        let testColorData = AvatarColor(color: .red, name: "Red")
        let viewModel = RegistrationViewModel()
        
        let colorPublisher = viewModel.avatarCellViewModel.updateColorPublisher
            .dropFirst()
        let namePublisher =  viewModel.colorCellViewModel.textValuePublisher
            .dropFirst()
        
        colorPublisher.sink { color in
            XCTAssert(color.isEqual(UIColor.red))
        }.store(in: &cancellable)
        
       
        namePublisher.sink { colorName in
            XCTAssert(colorName.isEqual("Red"))
        }.store(in: &cancellable)
        
        let expectation = XCTestExpectation(description: "test Avatar Color Setting")
        
        colorPublisher
            .combineLatest(namePublisher)
            .sink { _ in
                expectation.fulfill()
            }.store(in: &cancellable)
        
        viewModel.selectedAvatarColor(testColorData)
        
        wait(for: [expectation], timeout: 0.2)
    }
}
